<?php
// Use Connect Script
include("asn-config.php");
require_once('./class.rc4crypt.php');

class FGuestbook
{
    public function GetPosts()
    {
        $query = "SELECT * FROM posts ORDER BY id";
        $result = mysql_query($query);

        while ( $row = mysql_fetch_object($result) )
        {
            $arrayOfPosts[] = $row;
        }

        return $arrayOfPosts;
    }
	
	public function InsertPost($author, $email, $url, $message)
	{
		$d = date('d/m/Y , h:i:s');
		$query = "INSERT INTO posts VALUES('', '$author', '$email', '$url', '$d', '$message')";
		
		$result = mysql_query($query);
		
		return $result ? "inserted" : "error";
	}
	
	public function UpdatePost($id, $author, $email, $url, $message)
	{
		$query = "UPDATE posts SET author='$author', email='$email', url='$url', message='$message' WHERE id='$id'";
        $result = mysql_query($query);

        return $result ? "updated" : "error";
	}
	
	public function DeletePost($id)
	{
		$query = "DELETE FROM posts WHERE id = '$id'";
        $result = mysql_query($query);

        return $result ? "deleted" : "error";
	}
}

?>